package L5;

import java.util.Arrays;

import java.util.Scanner;

class Base64 {
    public final static char[] TABLE = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
                                        'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                                        '0','1','2','3','4','5','6','7','8','9','+','/'};
    public static String encode(byte[] raw) {
        
        StringBuilder result = new StringBuilder();
        int reminder = raw.length % 3;
        switch (reminder) {
            case 2:
                raw = Arrays.copyOf(raw, raw.length+1);
                break;
            case 1:
                raw = Arrays.copyOf(raw, raw.length+2);
            default:
                break;
        }
        char[] mid = new char[4];
        for (int i=0;i<raw.length/3;++i) {
            byte first = raw[i*3];
            byte second = raw[i*3+1];
            byte third = raw[i*3+2];
            int ind_4 = third & 0x3f;
            int ind_3 = ((second & 0xF) << 2) + (third >> 6);
            int ind_2 = ((first & 0x3) << 4) + (second >> 4);
            int ind_1 = first >> 2;
            mid[0] = TABLE[ind_1];
            mid[1] = TABLE[ind_2];
            mid[2] = TABLE[ind_3];
            mid[3] = TABLE[ind_4];
            result.append(new String(mid));
        }
        if (reminder != 0){
            result.delete(result.length()-(3-reminder), result.length());
            result.append("=".repeat(3-reminder));
        }
            
        return result.toString();
    }
}
public class TestBase64 {
    public static void main(String[] args) {
        
        String input;
        try (Scanner sc = new Scanner(System.in)) {
            while (!(input = sc.nextLine()).equals("!quit")){
                System.out.println(Base64.encode(input.getBytes()));
            }
        }
    }
}